package com.geoboard.service;

import java.util.ArrayList;

import com.geoboard.R;
import com.geoboard.entity.Board;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class ListAdapterBoard extends BaseAdapter{
	/**** Members *******************************************/
	private ArrayList<Board> data = null;
	private Context context = null;
	
	/**** Constructors **************************************/
	public ListAdapterBoard(ArrayList<Board> data, Context c)throws IllegalArgumentException{
		if(data == null || c == null){
			throw new IllegalArgumentException();
		}
		
		this.data = data;
		this.context = c;
	}
	
	/**** Base Adapter Overrides *****************************/

	@Override
	public int getCount() {
		return data.size();
	}

	@Override
	public Object getItem(int position) {
		return data.size();
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View v = convertView;
        if(v == null){
           LayoutInflater vi = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
           v = vi.inflate(R.layout.list_adap_board_row, null);
        }
        
        TextView tv = (TextView)v.findViewById(R.id.board_name);
        Board b = data.get(position);
        
        tv.setText(b.getName());
        
		
		return v;
	}

}
